#!/usr/bin/env python3
"""
Simple diagnosis script to check tool generation
"""

import yaml

def simple_diagnosis():
    """Simple diagnosis of configuration and expected tools"""
    
    print("🔍 Simple Tool Generation Diagnosis")
    print("=" * 50)
    
    # Read config file directly
    print("1. Reading config.yaml...")
    try:
        with open('config.yaml', 'r', encoding='utf-8') as f:
            config = yaml.safe_load(f)
        
        print("✅ Config loaded successfully")
        
        # Analyze services
        services = config.get('services', {})
        print(f"\n2. Found {len(services)} services in config:")
        
        total_expected_tools = 0
        
        for service_name, service_config in services.items():
            enabled = service_config.get('enabled', False)
            apis = service_config.get('apis', [])
            
            print(f"\n   📦 Service: {service_name}")
            print(f"      Enabled: {enabled}")
            print(f"      APIs configured: {len(apis)}")
            
            if enabled:
                enabled_apis = [api for api in apis if api.get('enabled', True)]
                print(f"      APIs enabled: {len(enabled_apis)}")
                
                for i, api in enumerate(enabled_apis):
                    method = api.get('method', 'N/A')
                    path = api.get('path', 'N/A')
                    description = api.get('description', 'N/A')
                    
                    # Generate expected tool name
                    tool_name = f"{service_name.upper()}_{method}_{path.replace('/', '_').replace('{', '').replace('}', '')}"
                    tool_name = tool_name.replace('-', '_').replace('.', '_')
                    
                    print(f"        {i+1}. {method} {path}")
                    print(f"           Description: {description}")
                    print(f"           Expected tool name: {tool_name}")
                    
                    total_expected_tools += 1
            else:
                print(f"      ⚠️  Service is disabled")
        
        print(f"\n3. Summary:")
        print(f"   Total expected tools: {total_expected_tools}")
        
        # Expected tools for icompute service
        print(f"\n4. Expected tools for icompute service:")
        icompute = services.get('icompute', {})
        if icompute.get('enabled', False):
            apis = icompute.get('apis', [])
            for api in apis:
                if api.get('enabled', True):
                    method = api.get('method')
                    path = api.get('path')
                    tool_name = f"ICOMPUTE_{method}_{path.replace('/', '_').replace('{', '').replace('}', '')}"
                    tool_name = tool_name.replace('-', '_').replace('.', '_')
                    print(f"   - {tool_name}")
        
        print(f"\n5. Potential issues to check:")
        print(f"   - Are all APIs available in Swagger documentation?")
        print(f"   - Do the method/path combinations match exactly?")
        print(f"   - Are there any errors during tool generation?")
        print(f"   - Check server logs for 'API not found in Swagger docs' warnings")
        
        return True
        
    except Exception as e:
        print(f"❌ Failed to read config: {e}")
        return False

if __name__ == '__main__':
    simple_diagnosis()
